package com.zjut.zs.userinfo.manager;

import java.util.List;

import javax.annotation.Resource;

import com.zjut.an.util.module.PageModule;
import com.zjut.common.idgen.IdGenerate;
import com.zjut.zs.user.dao.ZsUser;
import com.zjut.zs.userinfo.dao.ZsUserinfo;
import com.zjut.zs.userinfo.dao.ZsUserinfoDAO;
import com.zjut.zs.xy.dao.ZsXy;


public class ZsUserinfoManager {

	@Resource(name = "ZsUserinfoDAO")
	private ZsUserinfoDAO dao;

	@Resource(name = "IdGenerate")
	private IdGenerate idgenerate;
	
	public void addData(ZsUserinfo obj) {	
		obj.setInId(idgenerate.nextId());
		dao.save(obj);
	}
	
	public void updateData(ZsUserinfo obj) {
		dao.update(obj);
	}
	
	public void deleteData(ZsUserinfo obj) {
		dao.delete(obj);
	}

	public void deleteDatas(List<ZsUserinfo> objlist) {
		for (ZsUserinfo ZsUserinfo : objlist) {
			dao.delete(ZsUserinfo);
		}
	}
	
	public PageModule getDataByInstance (int pageNumber,int pageSize, String sort, String order, ZsUserinfo obj) {
		return dao.findByInstance(pageNumber, pageSize, sort, order, obj);
	}
	
	public List getDatas() {
		return dao.findAll();
	}

	public ZsUserinfo getData(String objId) {
		return dao.findById(objId);
	}
	

	public ZsUserinfo getDataByUser(ZsUser user) {
		ZsUserinfo obj = new ZsUserinfo();
		obj.setZsUser(user);
		if(this.getDataByInstance(1, 1, null, null, obj).getObjects().size()>0) {
			return (ZsUserinfo)this.getDataByInstance(1, 1, null, null, obj).getObjects().get(0);
		} else{
			return obj;
		}
	}
}
